package com.ams.protocol.rtmp.net;

import java.util.HashMap;

import com.ams.protocol.rtmp.RtmpConnection;

public class NetStreamManager {
    private HashMap<Integer, NetStream> streams;

    public NetStreamManager() {
        this.streams = new HashMap<Integer, NetStream>();
    }

    public NetStream get(int streamId) {
        return streams.get(streamId);
    }

    public NetStream createStream(RtmpConnection rtmp) {
        int id = 1;
        for (int len = streams.size(); id <= len; id++) {
            if (streams.get(id) == null)
                break;
        }
        NetStream stream = new NetStream(rtmp, id);
        streams.put(id, stream);
        return stream;
    }

    public void removeStream(NetStream stream) {
        streams.remove(stream.getStreamId());
    }

    public void clear() {
        streams.clear();
    }

}
